package gherkinedit.wizard;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class CreateTemplateWizardPage1 extends WizardPage {
	private Text templateName;
	private Text stepDefinition;
	private Composite container;

	public CreateTemplateWizardPage1() {
		super("Create Template");
		setTitle("Create a new Template");
		setDescription("Enter the name and step definition template to create a new Template");
	}

	@Override
	public void createControl(Composite parent) {
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		container = new Composite(parent, SWT.NULL);
		container.setLayout(layout);

		// Create template name input		
		Label label1 = new Label(container, SWT.NULL);
		label1.setText("Name");
		templateName = new Text(container, SWT.BORDER | SWT.SINGLE);
		templateName.setText("");
		templateName.addKeyListener(new KeyListener() {
			@Override
			public void keyPressed(KeyEvent e) {
			}

			@Override
			public void keyReleased(KeyEvent e) {
				if (!templateName.getText().isEmpty()) {
					setPageComplete(true);
				} else {
					setPageComplete(false);
				}
			}
		});

		// Create step definition regex input
		Label label2 = new Label(container, SWT.NULL);
		label2.setText("Step Def Template");
		stepDefinition = new Text(container, SWT.BORDER | SWT.SINGLE);
		stepDefinition.setText("");
		stepDefinition.addKeyListener(new KeyListener() {
			@Override
			public void keyPressed(KeyEvent e) {
			}

			@Override
			public void keyReleased(KeyEvent e) {
				if (!stepDefinition.getText().isEmpty()) {
					setPageComplete(true);
				} else {
					setPageComplete(false);
				}
			}
		});
		
		// Arrange layout
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
		templateName.setLayoutData(gd);
		stepDefinition.setLayoutData(gd);
		
		setControl(container);
		setPageComplete(false);

	}

	public String getTemplateName() {
		return new String(templateName.getText());
	}
	
	public String getTemplateRegex() {
		return new String(stepDefinition.getText());
	}
}
